home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- import java.util.Arrays;
-
- public class ByteArrayOutputStream extends OutputStream {
- protected byte[] buf;
- protected int count;
-
- public ByteArrayOutputStream() {
- this(32);
- }
-
- public ByteArrayOutputStream(int var1) {
- if (var1 < 0) {
- throw new IllegalArgumentException("Negative initial size: " + var1);
- } else {
- this.buf = new byte[var1];
- }
- }
-
- public synchronized void write(int var1) {
- int var2 = this.count + 1;
- if (var2 > this.buf.length) {
- this.buf = Arrays.copyOf(this.buf, Math.max(this.buf.length << 1, var2));
- }
-
- this.buf[this.count] = (byte)var1;
- this.count = var2;
- }
-
- public synchronized void write(byte[] var1, int var2, int var3) {
- if (var2 >= 0 && var2 <= var1.length && var3 >= 0 && var2 + var3 <= var1.length && var2 + var3 >= 0) {
- if (var3 != 0) {
- int var4 = this.count + var3;
- if (var4 > this.buf.length) {
- this.buf = Arrays.copyOf(this.buf, Math.max(this.buf.length << 1, var4));
- }
-
- System.arraycopy(var1, var2, this.buf, this.count, var3);
- this.count = var4;
- }
- } else {
- throw new IndexOutOfBoundsException();
- }
- }
-
- public synchronized void writeTo(OutputStream var1) throws IOException {
- var1.write(this.buf, 0, this.count);
- }
-
- public synchronized void reset() {
- this.count = 0;
- }
-
- public synchronized byte[] toByteArray() {
- return Arrays.copyOf(this.buf, this.count);
- }
-
- public synchronized int size() {
- return this.count;
- }
-
- public synchronized String toString() {
- return new String(this.buf, 0, this.count);
- }
-
- public synchronized String toString(String var1) throws UnsupportedEncodingException {
- return new String(this.buf, 0, this.count, var1);
- }
-
- /** @deprecated */
- @Deprecated
- public synchronized String toString(int var1) {
- return new String(this.buf, var1, 0, this.count);
- }
-
- public void close() throws IOException {
- }
- }
-